package cn.kilo.trigger.http.order;

import cn.kilo.domain.model.order.entity.OrderEntity;
import cn.kilo.domain.model.order.entity.OrderJudgeEntity;
import cn.kilo.domain.model.order.res.*;
import cn.kilo.domain.model.order.vo.OrderStatusVO;
import cn.kilo.domain.service.infterface.IOrderStrategyService;
import cn.kilo.domain.service.order.factory.DefaultFactory;
import cn.kilo.domain.support.QRCodeUtils;
import cn.kilo.trigger.api.IOrderService;
import cn.kilo.trigger.api.dto.order.OrderDTO;
import cn.kilo.types.enums.ResponseCode;
import cn.kilo.types.model.Response;
import com.alibaba.fastjson2.JSON;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author kilok
 */
@RestController
@Slf4j
@CrossOrigin("*")
@RequestMapping("api/order")
public class OrderController implements IOrderService {

    @Resource
    private IOrderStrategyService orderService;



    /**
     * 用户下订单
     * @param orderDTO
     * @return
     */
    @PostMapping("/create")
    @Override
    public Response<?> placeOrder(@RequestBody OrderDTO orderDTO) {
        try{
            log.info("开始下单:{}",orderDTO);
            List<OrderStatusVO> orderStatusVO = orderService.performJob(OrderEntity.builder()
                    .orderInfo(orderDTO.getOrderInfo())
                    .userId(orderDTO.getUserId())
                    .start(orderDTO.getStart())
                    .ridgepole(orderDTO.getRidgepole())
                    .end(orderDTO.getEnd())
                    .status("user")
                    .orderCode(orderDTO.getOrderCode())
                    .orderNumber(orderDTO.getOrderNumber())
                    .price(orderDTO.getPrice())
                    .build());
            if(orderStatusVO.get(0).getStatus().equals(DefaultFactory.Status.WRONG_POSITION.getInfo())){
                return Response.<String>builder()
                        .code(ResponseCode.ORDER_ERROR.getCode())
                        .info(ResponseCode.ORDER_ERROR.getInfo())
                        .data("下单失败")
                        .build();
            }
            return Response.<OrderStatusVO>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(orderStatusVO.get(0))
                    .build();
        }catch (Exception e){
            log.info("下单失败 :{}",e);
            return Response.<String>builder()
                    .code(ResponseCode.ORDER_ERROR.getCode())
                    .info(ResponseCode.ORDER_ERROR.getInfo())
                    .data("下单失败")
                    .build();
        }
    }

    /**
     * 用户上传订单图片
     * @param orderId
     * @param image
     * @return
     */
    @PostMapping("/updateOrderPicture")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "image",value = "MultipartFile")
    })
    @Override
    public Response<?> updateOrderPicture(@RequestParam("orderId") Long orderId, MultipartFile image) {
        try{
            String res=orderService.updateOrderPicture(orderId,image);
            return Response.<String>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(res)
                    .build();
        }catch (Exception e){
            log.info("订单图片上传失败:{}", e);
            return Response.<Boolean>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .build();
        }
    }

    /**
     * 获取未接单的订单信息，按照楼栋区分
     * @return
     */
    @PostMapping("/getCreateOrder")
    @Override
    public Response<?> getCreateOrder(@RequestBody OrderDTO orderDTO) {
        try{
            // TODO: 2024/5/11 查询对应楼栋的订单
            Integer size=orderService.getCreateOrderByRidgepole(OrderEntity.builder()
                    .ridgepole(orderDTO.getRidgepole())
                    .build());
            return Response.<Integer>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(size)
                    .build();
        }catch (Exception e){
            log.info("查询订单失败:{}",e);
            return Response.<Boolean>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .build();
        }
    }


    /**
     * 配送员接取订单
     * @param orderDTO
     * @return
     */
    @PostMapping("/takeOrder")
    @Override
    public Response<?> getOrder(@RequestBody OrderDTO orderDTO) {
        try{
            List<OrderStatusVO> orderStatusVO = orderService.performJob(OrderEntity.builder()
                    .sorter1(orderDTO.getSorter1())
                    .number(orderDTO.getNumber())
                    .ridgepole(orderDTO.getRidgepole())
                    .status("sorter1")
                    .build());
            log.info("接取的订单信息:{}", orderStatusVO);
            if(orderStatusVO==null){
                log.info("订单接取失败:{}",orderDTO);
                return Response.<String>builder()
                        .code(ResponseCode.UN_ERROR.getCode())
                        .info(ResponseCode.UN_ERROR.getInfo())
                        .data("订单接取失败,该订单已经被其他骑手接取")
                        .build();
            }
            return Response.<List<OrderStatusVO>>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(orderStatusVO)
                    .build();

        }catch (Exception e){
            log.info("订单接取失败:{}",e);
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("订单接取失败")
                    .build();
        }
    }



    /**
     * 查询配送员接取的订单
     * @param orderDTO
     * @return
     */
    @PostMapping("/getTokenOrder")
    @Override
    public Response<?> getTokenOrder(@RequestBody OrderDTO orderDTO) {
        try{
            Object[] tokenOrder = orderService.getTokenOrder(
                    OrderEntity.builder()
                            .sorter1(orderDTO.getSorter1())
                            .ridgepole(orderDTO.getRidgepole())
                            .build());
            return Response.<Object[]>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(tokenOrder)
                    .build();
        }catch (Exception e){
            log.info("对应接取订单查询失败",e);
            return Response.<Boolean>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .build();
        }
    }


    /**
     * 送至对应楼下生成二维码
     *
     * @param request
     * @param response
     * @param orderDTO
     * @return
     */
    @PostMapping("/getQRCodeByRidgepole")
    @Override
    public Response<?> generateQRCodeByRidgepole(HttpServletRequest request, HttpServletResponse response,
                                                 @RequestBody OrderDTO orderDTO) {
        try{
            // TODO: 2024/5/12  这里需要对楼栋做一个校验
            HashMap<String,Object> map=new HashMap<>();
            map.put("sorter1",orderDTO.getSorter1());
            MultipartFile multipartFile = QRCodeUtils.creatRrCode(JSON.toJSONString(map), 200, 200, response);
            log.info("fileName:{}",multipartFile.getOriginalFilename());
            String url = orderService.updateORCode(multipartFile);
            return Response.<String>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(url)
                    .build();
        }catch (Exception e){
            log.info("二维码生成失败:{}",e);
            return Response.<String>builder()
                    .data(ResponseCode.FAIL_OR_CODE.getCode())
                    .info(ResponseCode.FAIL_OR_CODE.getInfo())
                    .data("二维码生成失败")
                    .build();
        }
    }



    /**
     * 保安处通过扫码获取的信息，发送请求收取对应的订单信息
     * @param orderDTO
     * @return
     */
    @PostMapping("/getOrderByORCode")
    @Override
    public Response<?> getOrderByQRCode(@RequestBody OrderDTO orderDTO) {
        try{
            log.info("保安接取订单 guard:{},order+ridgepole:{}",orderDTO.getGuard());
            List<OrderStatusVO> orderStatusVOList = orderService.getOrderByQRCode(OrderEntity.builder()
                    .guard(orderDTO.getGuard())
                    .sorter1(orderDTO.getSorter1())
                    .ridgepole(orderDTO.getRidgepole())
                    .build()
            );
            if(null==orderStatusVOList||orderStatusVOList.size()==0){
                return Response.<String>builder()
                        .code(ResponseCode.UN_ERROR.getCode())
                        .info(ResponseCode.UN_ERROR.getInfo())
                        .data("没有订单可以分配")
                        .build();
            }
            return Response.<List<OrderStatusVO>>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(orderStatusVOList)
                    .build();
        }catch (Exception e){
            log.info("接取失败请重新扫码",e);
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("接取失败请重新扫码")
                    .build();
        }
    }

    /**
     * 保安查询已经接取了的订单
     * @param orderDTO
     * @return
     */
    @PostMapping("/getGuardOrder")
    @Override
    public Response<?> getGuardTokenOrder(@RequestBody OrderDTO orderDTO) {
        try{
            Collection<Object> objects = orderService.queryGuardOrder(OrderEntity.builder()
                    .guard(orderDTO.getGuard())
                    .ridgepole(orderDTO.getRidgepole())
                    .end(orderDTO.getEnd())
                    .build()
            );
            return Response.<Integer>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(objects.size())
                    .build();
        }catch (Exception e){
            log.info("订单信息获取失败:{}",e);
            return Response.<Boolean>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .build();
        }
    }

    /**
     * 根据寝室和楼层生成对应二维码
     *
     * @param request
     * @param response
     * @param orderDTO
     * @return
     */
    @PostMapping("/generateQRByFloor")
    @Override
    public Response<?> generateQRCodeByFloor(HttpServletRequest request, HttpServletResponse response,
                                             @RequestBody OrderDTO orderDTO) {
        try{
            HashMap<String,Object> map=new HashMap<>();
            map.put("ridgepole",orderDTO.getRidgepole());
            map.put("end",orderDTO.getEnd());
            map.put("number",orderDTO.getNumber());
            MultipartFile multipartFile = QRCodeUtils.creatRrCode(JSON.toJSONString(map), 200, 200, response);
            String url = orderService.updateORCode(multipartFile);
            return Response.<String>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(url)
                    .build();
        }catch (Exception e){
            log.info("二维码生成失败:{}",e);
            return Response.<String>builder()
                    .data(ResponseCode.FAIL_OR_CODE.getCode())
                    .info(ResponseCode.FAIL_OR_CODE.getInfo())
                    .data("二维码生成失败")
                    .build();
        }
    }

    /**
     * 寝室配送员接取订单
     *
     * @param orderDTO
     * @return
     */
    @PostMapping("/takeOrderFromGuard")
    @Override
    public Response<?> takeOrder(@RequestBody OrderDTO orderDTO) {
        try{
            log.info("开始接取订单:{}",orderDTO);
            List<OrderStatusVO> orderStatusVOList = orderService.takeOrderFromGuard(OrderEntity.builder()
                    .ridgepole(orderDTO.getRidgepole())
                    .end(orderDTO.getEnd())
                    .number(orderDTO.getNumber())
                    .sorter2(orderDTO.getSorter2())
                    .status("sorter2")
                    .build());
            if(null==orderStatusVOList||orderStatusVOList.size()==0){
                return Response.<String>builder()
                        .code(ResponseCode.UN_ERROR.getCode())
                        .info(ResponseCode.UN_ERROR.getInfo())
                        .data("该楼层对应的订单已经分配，请勿重复扫描无效二维码")
                        .build();
            }
            return Response.<List<OrderStatusVO>>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(orderStatusVOList)
                    .build();
        }catch (Exception e){
            log.info("订单接取失败",e);
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("订单接取失败")
                    .build();
        }
    }

    /**
     * 寝室配送员结束订单
     * @param orderDTO
     * @return
     */
    @PostMapping("/overOrder")
    @Override
    public Response<?> overOrder(@RequestBody OrderDTO orderDTO) {
        try{
            List<OrderStatusVO> orderStatusVO = orderService.performJob(OrderEntity.builder()
                    .orderId(orderDTO.getOrderId())
                    .sorter2(orderDTO.getSorter2())
                            .status("sorter2")
                    .build());
            return Response.<List<OrderStatusVO>>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(orderStatusVO)
                    .build();
        }catch (Exception e){
            log.info("订单结束失败",e);
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("订单结束失败")
                    .build();
        }
    }

    /**
     * 寝室配送员上传图片
     *
     * @param image
     * @param orderId
     * @return
     */
    @PostMapping("updateOverPicture")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "image",value = "MultipartFile")
    })
    @Override
    public Response<?> updateOverPicture(MultipartFile image,
                                         @RequestParam("orderId") Long orderId) throws IOException {

        try{
            String url=orderService.updateOverPicture(image,orderId);
            return Response.<String>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(url)
                    .build();
        }catch (Exception e){
            log.info(":{}",e);
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .code("未知错误，请重新上传二维码")
                    .build();
        }
    }

    /**
     * 用户确认订单
     * @param orderDTO
     * @return
     */
    @PostMapping("/userConfirmOrder")
    @Override
    public Response<?> userConfirmOrder(@RequestBody OrderDTO orderDTO) {
        try{
            List<OrderStatusVO> statusVO=orderService.performJob(OrderEntity.builder()
                            .orderId(orderDTO.getOrderId())
                            .status("over")
                    .build());
            return Response.<OrderStatusVO>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(statusVO.get(0))
                    .build();
        }catch (Exception e){
            log.info(":",e);
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("订单确认失败")
                    .build();
        }
    }

    @GetMapping("/getDepartment")
    @Override
    public Response<?> getDepartment() {
        try{
            List<DepartmentRes> res=orderService.getDepartment();
            return Response.<List<DepartmentRes>>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(res)
                    .build();
        }catch (Exception e){
            log.info("公寓信息获取失败:{}",e);
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("公寓信息获取失败")
                    .build();
        }
    }

    /**
     * 获取寝室配送员当前的接单信息
     */
    @PostMapping("/getOrderInfoList")
    @Override
    public Response<?> getOrderInfoList(@RequestBody OrderDTO orderDTO) {
        try{

            Collection<Object> orderInfoList = orderService.getOrderInfoList(
                    OrderEntity.builder()
                    .sorter2(orderDTO.getSorter2())
                    .build());
            return Response.<Collection<Object>>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(orderInfoList)
                    .build();
        }catch (Exception e){
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("订单信息获取失败")
                    .build();
        }
    }

    /**
     * 用户获取对应订单状态
     * @param orderDTO
     * @return
     */
    @PostMapping("/userGetOrderInfo")
    @Override
    public Response<?> userGetOrderInfo(@RequestBody OrderDTO orderDTO) {
        try{

            OrderStatusVO orderStatusVO =
                    orderService.userGetOrderInfo(OrderEntity.builder()
                            .orderId(orderDTO.getOrderId())
                            .build());
            return Response.<OrderStatusVO>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(orderStatusVO)
                    .build();
        }catch (Exception e){
            log.info(":",e);
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("订单信息获取失败")
                    .build();
        }
    }

    /**
     * 获取用户正在进行的订单
     * @param orderDTO
     * @return
     */
    @PostMapping("/getUserOrder")
    @Override
    public Response<?> getUserOrder(@RequestBody OrderDTO orderDTO) {
        try{
            List<OrderStatusVO> list=orderService.getUserOrder(orderDTO.getUserId(),"用户确认收货");
            return Response.<List<OrderStatusVO>>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(list)
                    .build();
        }catch (Exception e){
            log.info(":",e);
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("用户订单信息获取失败")
                    .build();
        }
    }

    @PostMapping("/judge")
    @Override
    public Response<?> judgeOrder(OrderDTO orderDTO) {
        try{
            boolean res=orderService.JudgeOrder(OrderJudgeEntity
                    .builder()
                    .userId(orderDTO.getUserId())
                    .orderId(orderDTO.getOrderId())
                    .info(orderDTO.getOrderInfo())
                    .type(orderDTO.getType())
                    .build());
            return res?Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("评价失败,已经评价过")
                    .build():
                    Response.<String>builder()
                            .code(ResponseCode.SUCCESS.getCode())
                            .info(ResponseCode.SUCCESS.getInfo())
                            .data("评价成功")
                            .build();
        }catch (Exception e){
            log.info(":",e);
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("评价失败")
                    .build();
        }
    }

    @GetMapping("/getOrderNumber")
    @Override
    public Response<?> getOrderNumber() {
        try {
            return Response.<Integer>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(Integer.parseInt(orderService.getOrderNum()))
                    .build();
        }catch (Exception e){
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .build();
        }
    }

    /**
     * 骑手设置天气
     */
    @PostMapping("/weather")
    @Override
    public Response<?> setWeather(OrderDTO orderDTO) {
        try{
            String str=orderService.setWeather(orderDTO.getUserId(),orderDTO.getWeather());
            return Response.<String>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(str)
                    .build();
        }catch (Exception e){
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .build();
        }
    }

    /**
     * 获取所有的评价
     * @return
     */
    @GetMapping("/getAllBadJudgement")
    @Override
    public Response<?> getAllJudgement(String type) {
        try{
            List<JudgeRes> list=orderService.getBadJudge(type);
            return Response.<List<JudgeRes>>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(list)
                    .build();
        }catch (Exception e){
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .build();
        }
    }

    /**
     * 获取对应职位剩余位置
     * @param orderDTO
     * @return
     */
    @PostMapping("/getLeftStaff")
    @Override
    public Response<?> getLeftStaff(OrderDTO orderDTO) {
        try{
            Map<String,Integer> map=orderService.getLeftStaff(OrderEntity
                    .builder()
                            .role(orderDTO.getRole())
                            .ridgepole(orderDTO.getRidgepole())
                            .end(orderDTO.getEnd())
                    .build());
            if(null==map){
                return Response.<String>builder()
                        .code(ResponseCode.UN_ERROR.getCode())
                        .info(ResponseCode.UN_ERROR.getInfo())
                        .data("职位信息获取失败")
                        .build();
            }
            return Response.<Map<String,Integer>>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(map)
                    .build();
        }catch (Exception e){
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("职位信息获取失败")
                    .build();
        }
    }

    /**
     * 获取公寓分组信息
     * @return
     */
    @GetMapping("getDepartmentGroup")
    @Override
    public Response<?> getDepartmentGroup() {
        try {
            List<DepartRes> departmentGroup = orderService.getDepartmentGroup();
            return Response.<List<DepartRes>> builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(departmentGroup)
                    .build();
        }catch (Exception e){
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("信息获取失败")
                    .build();

        }
    }

    @GetMapping("/getPosition")
    @Override
    public Response<?> getPosition() {
        List<String> ans=orderService.getPosition();
        return Response.<List<String>>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .info(ResponseCode.SUCCESS.getInfo())
                .data(ans)
                .build();
    }

    @PostMapping("/getFloor")
    @Override
    public Response<?> getFloor(@RequestBody OrderDTO orderDTO) {
        try {
            List<FloorRes> floor = orderService.getFloor(orderDTO.getRidgepole());
            return Response.<List<FloorRes>>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(floor)
                    .build();
        }catch (Exception e){
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("楼层信息获取失败")
                    .build();
        }
    }

    @PostMapping("/getStaff")
    @Override
    public Response<?> getStaff(@RequestBody OrderDTO orderDTO) {
        try {
            StaffRes staff = orderService.getStaff(orderDTO.getStaffId());

            return Response.<StaffRes>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(staff)
                    .build();
        }catch (Exception e){
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("员工信息获取失败")
                    .build();
        }
    }

    /**
     * 生成二维码
     * @param request
     * @param response
     * @param content
     * @throws Exception
     */
    @GetMapping("/qrcode")
    public void qrcode(HttpServletRequest request, HttpServletResponse response,
                       @RequestParam(name = "content") String content) throws Exception {
        if (StringUtils.isBlank(content)) {
            response.sendRedirect("/404.html");
            return;
        }
        //调用工具类，生成二维码
        QRCodeUtils.creatRrCode(content, 200,200,response);
    }

}
